import { Application } from 'egg';
import { STRING, INTEGER, Optional, Model } from 'sequelize';

export interface MessageAttributes {
  messageId: number;
  sendUserId: number,
  receiveUserId: number,
  message: string;
  time: number;
}

interface MessageCreationAttributes extends Optional<MessageAttributes, 'messageId'> {}

export default (app: Application) => {
  const User = app.model.define<Model<MessageAttributes, MessageCreationAttributes>>('message', {
    messageId: { type: INTEGER, primaryKey: true, autoIncrement: true, field: 'messageId' },
    sendUserId: { type: INTEGER, allowNull: false, field: 'sendUserId' },
    receiveUserId: { type: INTEGER, allowNull: false, field: 'receiveUserId' },
    message: { type: STRING(1000), allowNull: false },
    time: { type: INTEGER, allowNull: false },
  }, {
    timestamps: false,
  });

  return User;
};
